package com.hzsai.nettylearn.server;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * hzsai 2019/11/15
 * usage: 伪异步IO执行线程池
 **/
public class FakeAsyncTimeThreadPoolExecutor {

    private int poolSize;

    private int queueSize;

    ThreadPoolExecutor executor;

    public FakeAsyncTimeThreadPoolExecutor(int poolSize, int queueSize) {

        this.poolSize = poolSize;
        this.queueSize = queueSize;

        executor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(),
                poolSize, 120L, TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(queueSize));
    }

    public void execute(java.lang.Runnable s) {
        executor.execute(s);
    }

    public int getPoolSize() {
        return executor.getPoolSize();
    }
}
